package com.example.contact

import com.example.contact.model.Contact
import com.example.contact.dao.ContactDao
import com.example.featuresdk.database.DatabaseCallback
import com.example.featuresdk.model.User
import com.example.featuresdk.dao.UserDao
import javax.inject.Inject

class ContactDatabaseCallback
@Inject constructor(
    private val userDao: UserDao,
    private val contactDao: ContactDao
): DatabaseCallback() {

    override suspend fun initialize() {

        super.initialize()

        val users = userDao.getAll()

        //initialize contacts (just a subset of all users)
        val contacts = mutableListOf<Contact>().apply {
            addAll(users.subList(1,5).map {
                Contact(User.ME.id!!, it.id!!)
            })
            addAll(users.subList(5,10).map {
                Contact(
                    User.ME.id!!,
                    it.id!!,
                    name = "${it.nickname}"
                )
            })
        }
        contactDao.insert(contacts)
    }
}